import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

import com.google.code.jholidays.core.DescriptorCollection;
import com.google.code.jholidays.core.EventBuilder;
import com.google.code.jholidays.events.IEvent;
import com.google.code.jholidays.exceptions.NotSupportedEventException;
import com.google.code.jholidays.io.IDescriptorReader;
import com.google.code.jholidays.io.jdbc.JdbcReader;

public class Main {

    /**
     * @param args
     * @throws NotSupportedEventException
     * @throws IllegalArgumentException
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static void main(String[] args) throws IllegalArgumentException,
	    NotSupportedEventException, ClassNotFoundException, SQLException {

	// FloatingParser floatingParser = new FloatingParser();
	// Date date = parser.getDate("3%Mon%Aug", 2009);
	// System.out.print(date);

	// OffsetParser offsetPareser = new OffsetParser();
	// Offset o = offsetPareser.parseOffset("32");
	// System.out.println(o);

	// FixedParser fixedParser = new FixedParser();
	// Date date = fixedParser.parseDate("1.12", 2009);
	// System.out.print(date);

	/*
	 * EasterPlugin e = new EasterPlugin();
	 * 
	 * for (int i = 2009; i < 2030; ++i) System.out.println(e.getDate(i));
	 */

	// ===PostgreSQL===
	//
	// String url = "jdbc:postgresql://127.0.0.1:5432/db_name";
	// Properties props = new Properties();
	// props.setProperty("user", "login");
	// props.setProperty("password", "pass");
	// Connection conn = DriverManager.getConnection(url, props);

	// ===MySQL===
	//
	// Connection conn = DriverManager
	// .getConnection("jdbc:mysql://localhost/db_name?user=login&password=pass");

	// ===MSSQL===
	//
	// Connection conn = DriverManager
	// .getConnection("jdbc:sqlserver://localhost:1433;databaseName=db_name;"
	// + "user=login;password=pass;");

	// ===Sqlite===
	//
	Class.forName("org.sqlite.JDBC");
	Connection conn = DriverManager.getConnection("jdbc:sqlite:test_db");

	IDescriptorReader reader = new JdbcReader(conn, "event_descriptors");
	DescriptorCollection coll = reader.read();

	System.out.println(coll.size());

	EventBuilder builder = new EventBuilder();
	List<IEvent> events = builder.buildEvents(coll);

	final int year = 2009;

	for (IEvent event : events) {
	    System.out.println(event.getDate(year));
	}
    }
}
